package cn.xzchain.concurrency.singleton;

import cn.xzchain.concurrency.annoations.ThreadSafe;

/**
 * @author lihang
 * @date 2018/5/7.
 * @description 饿汉模式--线程安全，使用静态代码块
 */
@ThreadSafe
public class Singleton6 {

    private Singleton6(){
    }

    //要写在静态代码块前面才能保证被正确赋值
    private static Singleton6 instance = null;

    static {
        instance = new Singleton6();
    }


    /**静态工厂模式*/
    public static Singleton6 getInstance(){
        return instance;
    }
}
